package com.example.interceptor;

import lombok.Data;

@Data
public class Result<T> {
    private int code; //-1 未登录    200 正常  -2 出错
    private String ErrMsg;
    private T data;
    public static <T> Result success(T data){
        Result result = new Result();
        result.setCode(200);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

    public static <T> Result fail(String errMsg){
        Result result = new Result();
        result.setCode(-2);
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }

    public static <T> Result fail(String errMsg, T data){
        Result result = new Result();
        result.setCode(-2);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }

    public static <T> Result unlogin(){
        Result result = new Result();
        result.setCode(-1);
        result.setErrMsg("用户未登录");
        return result;
    }
}
